﻿CREATE PROCEDURE [dbo].[proc_Statistics_Financial_CreateDaily]
	(
		@IBA decimal(18,2),
		@IBB decimal(18,2),
		@IBC decimal(18,2),
		@CreateUser nvarchar(50),
		@CreateDate datetime,
		@CompanyId INT,
		@CompanyName NVARCHAR(100)
	)
AS
BEGIN
		IF @CreateUser='' OR @CreateUser IS NULL
	BEGIN
		RETURN
	END
	
	Declare @temp INT
	--, @CompanyName nvarchar(50)
	Select @temp=Count(Id) From Statistics_Financial Where CompanyId=@CompanyId and Convert(nchar(10),CreateDate,120)=Convert(nchar(10),@CreateDate,120)
	--Select @CompanyName=CompanyName From Company Where Id=@CompanyId
	if(@temp=0)
		Begin
			Insert Into Statistics_Financial
			(
				IBA
				,IBB
				,IBC
				,CreateUser
				,CreateDate
				,CompanyId
				,CompanyName
			)
			Values
			(
				@IBA
				,@IBB
				,@IBC
				,@CreateUser
				,@CreateDate
				,@CompanyId
				,@CompanyName
			)
		End
	else
		Begin
			Update Statistics_Financial Set
				IBA=@IBA
				,IBB=@IBB
				,IBC=@IBC
				,CreateUser=@CreateUser
			Where CompanyId=@CompanyId and Convert(nchar(10),CreateDate,120)=Convert(nchar(10),@CreateDate,120)
		End
End
	RETURN